package com.dhy.socket.controller;

import com.dhy.dao.CourseDao;
import com.dhy.domain.Course;
import com.dhy.socket.anno.Controller;
import com.dhy.socket.anno.GetMapping;
import com.dhy.socket.anno.PostMapping;
import com.dhy.socket.anno.RequestParam;
import com.dhy.socket.res.AjaxResponse;

/**
 * @author 大忽悠
 * @create 2022/6/20 22:40
 */
@Controller
public class CourseController {
    private final CourseDao courseDao=new CourseDao();

    @GetMapping("/listCourse")
    public AjaxResponse listCourse(){
     return AjaxResponse.success(courseDao.list());
    }

    /**
     * 查询某课程所有学生得分情况
     */
    @GetMapping("/queryStudByCno")
    public AjaxResponse queryStudByCno(@RequestParam("cno")String cno){
        return AjaxResponse.success(courseDao.queryStudByCno(cno));
    }

    @PostMapping("/insertOneCourse")
    public AjaxResponse insertCourse(@RequestParam("type")Integer type,
                                     @RequestParam("credits")Integer credits,
                                     @RequestParam("majorId")Integer majorId,
                                     @RequestParam("name")String name){
        return AjaxResponse.success(courseDao.insert(Course.builder().type(String.valueOf(type)).name(name).majorId(majorId).credits(credits).build()));
    }


}
